import java.util.Scanner;

//实践炸娃基础第一部分 数据类型--->堆栈
public class practice_01 {
    public static void main(String[] args) {
        lockKey();
    }

    //    Test1：买飞机票
//    输入:机票原价，月份，经济舱(0)或者头等舱(1)
//    计算：月份（5-10）头等舱9折，经济舱8.5折，月份（11-4）头等舱7折，经济舱6.5折
//    输出：机票价格
    public static void buyTicket() {
        Scanner sc = new Scanner(System.in);
        double ticket;
        int month;
        int Type;
        double price;
        System.out.print("输入机票原价:");
        ticket = sc.nextDouble();
        System.out.print("输入月份:");
        month = sc.nextInt();
        System.out.print("输入经济舱（0）头等舱（1）:");
        Type = sc.nextInt();
        if (Type == 0) {
            if (month >= 5 && month <= 10) {
                price = ticket * 0.85;
                System.out.println("实际价格为:" + price);
            } else if (month >= 1 && month <= 4 || month >= 11 && month <= 12) {
                price = ticket * 0.65;
                System.out.println("实际价格为:" + price);
            } else {
                System.out.println("月份输入不合法");
            }
        } else if (Type == 1) {
            if (month >= 5 && month <= 10) {
                price = ticket * 0.9;
                System.out.println("实际价格为:" + price);
            } else if (month >= 1 && month <= 4 || month >= 11 && month <= 12) {
                price = ticket * 0.7;
                System.out.println("实际价格为:" + price);
            } else {
                System.out.println("月份输入不合法");
            }
        } else {
            System.out.println("经济舱或者头等舱输入不合法");
        }

    }

    //    Test2:找出100-200之间的所有素数
//    输入:无
//    输出:素数的个数以及它们本身
    public static void findSuShu() {
        int count = 0;
        System.out.println("素数有:");
        for (int i = 100; i <= 200; i++) {
            boolean flag = true;
            for (int j = 2; j <= Math.sqrt(i); j++) {
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                count++;
                System.out.print(i + " ");
            }
        }
        System.out.println("共" + count + "个");
    }

    //密码加密:
/* 输入:一个大于0得正整数
   要求:各位数字+5，%10后组成新的数字并翻转 --->1259 ==>4076
 */
    public static int lockKey() {
        Scanner sc = new Scanner(System.in);
        System.out.print("输入要加密得数字:");
        int num = sc.nextInt();
        int num2 = num;
        int count = 0;
//        获取位数
        while (num2 > 0) {
            num2 = num2 / 10;
            count++;
        }
        int[] arr = new int[count];
//        数字各位倒着放入数组
        for (int i = 0; i < arr.length; i++) {
            arr[i] = num % 10;
            num = num / 10;
        }
//        +5
        for (int i = 0; i < arr.length; i++) {
            arr[i] += 5;
        }
//        %10
        for (int i = 0; i < arr.length; i++) {
            arr[i] %= 10;
        }
        int result = 0;
        for (int i = 0; i < arr.length; i++) {
            result = result * 10 + arr[i];
        }
        System.out.println("加密后的数:" + result);
        unLockKey(result);
        return result;
    }

    //    解密 将以上代码加密数字解密还原
    public static void unLockKey(int num) {
        int num2 = num;
        int count = 0;
        while (num2 > 0) {
            num2 /= 10;
            count++;
        }
        int arr[] = new int[count];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = num % 10;
            num /= 10;
        }
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] >= 0 && arr[i] <= 4) {
                arr[i] += 10;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i] -= 5;
        }
        int result = 0;
        for (int i = 0; i < arr.length; i++) {
            result = result * 10 + arr[i];
        }
        System.out.println("解密后的数:" + result);
    }
}